#ifndef CONFIG_H
#define CONFIG_H

#include <string>
#include <vector>
#include <unordered_map>

enum class Scheme
{
    NORM, // Normal (unselected)
    SEL,  // Selected
    OUT,  // Output
    LAST
};

enum class ShortcutAction
{
    NONE,
    CURSOR_HOME,
    CURSOR_END,
    CURSOR_LEFT,
    CURSOR_RIGHT,
    CURSOR_WORD_LEFT,
    CURSOR_WORD_RIGHT,
    DELETE_LEFT,
    DELETE_RIGHT,
    DELETE_WORD,
    DELETE_ALL,
    COMPLETE,
    SELECT_UP,
    SELECT_DOWN,
    SELECT_FIRST,
    SELECT_LAST,
    PAGE_UP,
    PAGE_DOWN,
    PASTE_PRIMARY,
    PASTE_CLIPBOARD,
    EXIT,
    SUBMIT,
    SUBMIT_KEEP_OPEN
};

struct Color
{
    uint32_t r, g, b, a;
    static Color fromHex(const std::string &hex);
};

struct Config
{
    bool topbar = false;
    int lines = 5;
    // TODO: can not preview ❯, maybe utf8 issue
    std::string prompt = "❯ ";
    bool centered = false;
    int min_width = 500;
    float menu_height_ratio = 5.0f;
    std::string word_delimiters = " /?\"&[](){}<>|;:,.!@#$%^&*~";
    bool case_insensitive = false;
    bool fast_mode = false;
    int monitor = -1;
    uint64_t embed_window = 0;

    std::vector<std::string> fonts = {
        "Noto Sans:size=32",
        "WenQuanYi Micro Hei:size=32",
        "sans-serif:size=32"};

    Color colors[(size_t)Scheme::LAST][2] = {
        {Color::fromHex("#f8f8f2"), Color::fromHex("#282a36")}, // NORM: FG/BG
        {Color::fromHex("#ffffff"), Color::fromHex("#bd93f9")}, // SEL: FG/BG
        {Color::fromHex("#282a36"), Color::fromHex("#50fa7b")}  // OUT: FG/BG
    };

    std::unordered_map<uint32_t, ShortcutAction> shortcuts = {
        {0x41 | (1 << 2), ShortcutAction::CURSOR_HOME},
        {0x42 | (1 << 2), ShortcutAction::CURSOR_LEFT},
        {0x43 | (1 << 2), ShortcutAction::EXIT},
        {0x44 | (1 << 2), ShortcutAction::DELETE_RIGHT},
        {0x45 | (1 << 2), ShortcutAction::CURSOR_END},
        {0x46 | (1 << 2), ShortcutAction::CURSOR_RIGHT},
        {0x48 | (1 << 2), ShortcutAction::DELETE_LEFT},
        {0x49 | (1 << 2), ShortcutAction::COMPLETE},
        {0x4A | (1 << 2), ShortcutAction::SUBMIT},
        {0x4D | (1 << 2), ShortcutAction::SUBMIT},
        {0x4E | (1 << 2), ShortcutAction::SELECT_DOWN},
        {0x50 | (1 << 2), ShortcutAction::SELECT_UP},
        {0x55 | (1 << 2), ShortcutAction::DELETE_ALL},
        {0x57 | (1 << 2), ShortcutAction::DELETE_WORD},
        {0x59 | (1 << 2), ShortcutAction::PASTE_PRIMARY},
        {0xFF09, ShortcutAction::COMPLETE},
        {0xFF50, ShortcutAction::CURSOR_HOME},
        {0xFF57, ShortcutAction::CURSOR_END},
        {0xFF51, ShortcutAction::CURSOR_LEFT},
        {0xFF53, ShortcutAction::CURSOR_RIGHT},
        {0xFF52, ShortcutAction::SELECT_UP},
        {0xFF54, ShortcutAction::SELECT_DOWN},
        {0xFF55, ShortcutAction::PAGE_UP},
        {0xFF56, ShortcutAction::PAGE_DOWN},
        {0xFF08, ShortcutAction::DELETE_LEFT},
        {0xFFFF, ShortcutAction::DELETE_RIGHT},
        {0xFF1B, ShortcutAction::EXIT},
        {0xFF0D, ShortcutAction::SUBMIT},
        {0xFF8D, ShortcutAction::SUBMIT}};

    bool loadFromFile(const std::string &path = "");
    bool loadFromArgs(int argc, char *argv[]);
};

void usage(); // Print command-line help

#endif // CONFIG_H
